package com.Lixiaoqian.Gulangyu.fragments


import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.view.ViewPager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.Lixiaoqian.Gulangyu.R
import com.Lixiaoqian.Gulangyu.adapter.BannerAdapter
import com.Lixiaoqian.Gulangyu.route_m.bean.RouteBean
import kotlinx.android.synthetic.main.fragment_route.*
import java.util.*


/**
 * A simple [Fragment] subclass.
 */
class RouteFragment : Fragment(),ViewPager.OnPageChangeListener{
    lateinit var list:List<RouteBean>
    override fun onPageScrollStateChanged(state: Int) {
    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
    }

    override fun onPageSelected(position: Int) {
        wd_indic.setSelectNum(position)
    }

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        return inflater?.inflate(R.layout.fragment_route, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        list = ArrayList<RouteBean>().apply {
            add(RouteBean("zibo", 1, 2, "http://img.taopic.com/uploads/allimg/120727/201995-120HG1030762.jpg"))
            add(RouteBean("123", 1, 2, "http://img.taopic.com/uploads/allimg/120727/201995-120HG1030762.jpg"))
            add(RouteBean("12323", 1, 2, "http://img.taopic.com/uploads/allimg/120727/201995-120HG1030762.jpg"))
        }
        val bannerAdapter = BannerAdapter(this@RouteFragment.context)
        bannerAdapter.setData(list)
        wd_banner_pager.setAdapter(bannerAdapter)
        wd_banner_pager.addOnPageChangeListener(this)

        wd_indic.setDataList(list)
    }

    override fun onResume() {
        super.onResume()
        wd_banner_pager.startAutoScroll()
    }

    override fun onPause() {
        super.onPause()
        wd_banner_pager.stopAutoScroll()
    }


}// Required empty public constructor
